﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YTCMS.Core;
using YTCMS.Domain.Entities;
using YTCMS.Services.Services;

namespace Admin.Controllers
{
    public class CustomController : Controller
    {
        //
        // GET: /Custom/
        private readonly IcustomService _custom;
        public CustomController(IcustomService custom)
        {
            this._custom = custom;
        }

        public ActionResult Index(int? pageIndex = 1, int? pageSize = 10)
        {
            int pcount = 0;
            var model = _custom.PageList(s => true, pageIndex.Value - 1, pageSize.Value, out pcount);
            ViewBag.PageSize = pageSize.Value;
            ViewBag.TotalCount = pcount;
            return View(model);
        }
        public ActionResult Search(string pname, int? pageIndex = 1, int? pageSize = 10)
        {
            int pcount = 0;
            var model = _custom.GetMany(s => true);
            model = QueryHelper.WhereIf<custom>(model, s => s.Contact.Contains(pname), !string.IsNullOrWhiteSpace(pname));
            model = _custom.PageList(model, pageIndex.Value - 1, pageSize.Value, out pcount);
            ViewBag.PageSize = pageSize.Value;
            ViewBag.TotalCount = pcount;
            return PartialView("List", model);
        }

        public JsonResult Delete(int id)
        {
            var model = _custom.Get(s => s.Id == id);
            _custom.Delete(model);
            return new JsonResult() { Data = true, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }
	}
}